Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Update get_github_installation_ids to use httpx #6451

Merged
merged 3 commits into from
Jan 27, 2025

Conversation

tofarr
Copy link
Collaborator

@tofarr tofarr commented Jan 24, 2025

This PR updates the get_github_installation_ids function to use httpx instead of requests with call_sync_from_async. This change makes the code more consistent with other functions in the file and more efficient by using native async HTTP requests.

Changes:

  • Replace requests with httpx.AsyncClient()
  • Use async context manager for better resource management
  • Update error handling to use httpx.HTTPError
  • Remove explicit response.close() as it is handled by the context manager
  • Make the code pattern consistent with other functions in the file

To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0e13a48-nikolaik   --name openhands-app-0e13a48   docker.all-hands.dev/all-hands-ai/openhands:0e13a48

@tofarr tofarr marked this pull request as ready for review January 25, 2025 12:49
Copy link
Contributor

@malhotra5 malhotra5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@amanape amanape left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change! Why not create a generic async fetch from now, too?

E.g.:

async def async_fetch(
    method: str = 'GET',
    url: str = '',
    headers: dict = None,
    params: dict = None,
):
    try:
        async with httpx.AsyncClient() as client:
            response = await client.request(
                method=method.upper(),
                url=url,
                headers=headers,
                params=params,
            )
            response.raise_for_status() 
            return response.json() 
    except httpx.HTTPError as e:
        #  Handle HTTP errors
        raise Exception(f'HTTP error: {e}')
    except Exception as e:
        # Handle other exceptions
        raise Exception(f'Error: {e}')

@tofarr
Copy link
Collaborator Author

tofarr commented Jan 27, 2025

Good change! Why not create a generic async fetch from now, too?

E.g.:

async def async_fetch(
    method: str = 'GET',
    url: str = '',
    headers: dict = None,
    params: dict = None,
):
    try:
        async with httpx.AsyncClient() as client:
            response = await client.request(
                method=method.upper(),
                url=url,
                headers=headers,
                params=params,
            )
            response.raise_for_status() 
            return response.json() 
    except httpx.HTTPError as e:
        #  Handle HTTP errors
        raise Exception(f'HTTP error: {e}')
    except Exception as e:
        # Handle other exceptions
        raise Exception(f'Error: {e}')

I like this idea - I'll do it in a later PR when there's time.

@tofarr tofarr merged commit 8a65df6 into main Jan 27, 2025
16 checks passed
@tofarr tofarr deleted the update-github-installations branch January 27, 2025 16:59
zchn pushed a commit to zchn/OpenHands that referenced this pull request Feb 4, 2025
idagelic pushed a commit to idagelic/OpenHands that referenced this pull request Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants